n = int(input())
nums = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = nums[0]
ans = dp[0]
for i in range(1, n):
    dp[i] = max(dp[i - 1] + nums[i], nums[i])
    ans = max(ans, dp[i])
print(ans)

ans = nums[0]
val = nums[0]
for i in range(1, n):
    val = max(val + nums[i], nums[i])
    ans = max(ans, val)
print(ans)

ans = nums[0]
ai = 0
aj = 0
val = nums[0]
for i in range(1, n):
    if val + nums[i] < nums[i]:
        ai = i
    val = max(val + nums[i], nums[i])
    if val > ans:
        aj = i
        ans = val
